<?php

namespace app\controllers;


use app\librarys\BaseController;

use app\models\Department;

use app\models\Manager;
use Yii;

class CommonController extends BaseController
{
    /**
     * 获取部门树形结构数据
     * @return string
     */
    public function actionDepartmentTreeHandler()
    {
        $manager = Manager::getCurrentManager();
        $institution_code = \Yii::$app->request->post('institution_code', $manager['institution_code']);
        $manager_id = $manager['id'];

        $departments = null;
        if (Department::isDepartmentManager($manager_id)) {
            $departments = Department::getListTree2($institution_code, $manager_id);
        } else {
            $departments = Department::getListTree($institution_code);
        }

        return $this->renderJson($departments, 0, '');
    }


}